<?php

namespace App\Http\Controllers;

use App\Models\Setting;
use Illuminate\Http\Request;

class AppController extends Controller
{
    public function index()
    {
        if(!test_wechat()) {
            return view('scan', [
                'script' => '<script></script>',
                'data' => ['message'=>'仅支持手机微信访问','code'=>402]
            ]);
        }
        $Wechat = $this->wechat();
        $_data = $Wechat->jssdk->buildConfig(
            ['onMenuShareTimeline','onMenuShareAppMessage','updateAppMessageShareData','updateTimelineShareData','chooseWXPay','hideMenuItems','getLocation','scanQRCode','hideAllNonBaseMenuItem','showMenuItems'],
            false,
            false,
            true,
            ['wx-open-subscribe']
        );
        $_script = "<script src='//webapi.amap.com/maps?v=1.4.15&key=".Setting::value('map_key')."&plugin=AMap.Geolocation,AMap.Geocoder'></script>";
        $_script .= "<script src='//res.wx.qq.com/open/js/jweixin-1.6.0.js'></script>";
        $_script .= "<script>wx.config(".$_data.")</script>";
        $_script .= "<script>window.cool = {app_name: '".Setting::value('website_name')."'}</script>";
        return view("app", ["script"=>$_script]);
    }
}
